<template>
    <div>
        <el-breadcrumb separator="/" class="m-b-25">
            <el-breadcrumb-item><a href="/">后台首页</a></el-breadcrumb-item>
            <el-breadcrumb-item><a href="/type">分类管理</a></el-breadcrumb-item>
            <el-breadcrumb-item>编辑分类</el-breadcrumb-item>
        </el-breadcrumb>

        <el-form ref="form" :model="form" label-width="80px" class="m-t-10">
            <el-form-item label="分类">
                <el-radio-group v-model="form.radio1">
                    <el-radio-button label="视频"></el-radio-button>
                    <el-radio-button label="音频"></el-radio-button>
                    <el-radio-button label="文章"></el-radio-button>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="类型">
                <el-radio-group v-model="form.radio2">
                    <el-radio-button label="欣赏"></el-radio-button>
                    <el-radio-button label="展示"></el-radio-button>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="分类名称">
                <el-input ref="name" v-model="form.name" placeholder="请输入分类名称"></el-input>
            </el-form-item>

            <el-form-item label="分类排序">
                <el-input ref="sort" type="number" v-model="form.sort" placeholder="请输入分类排序，（默认排序：0）"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="success" @click="submit">修改</el-button>
                <el-button type="danger" @click="cancel">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {
        get,
        put
    } from '@/network/request'
    export default {
        name: 'EditType',
        data() {
            return {
                form: {
                    id: this.$route.params.id,
                    name: '',
                    radio1: '视频',
                    radio2: '欣赏',
                    sort: ''
                }
            }
        },
        mounted() {
            get('/editType', {
                id: this.$route.params.id
            }).then(res => {
                const result = res.data
                if (result.code == 200) {
                    this.form.name = result.data.name
                    this.form.sort = String(result.data.sort)
                    switch (result.data.pid) {
                        case 1:
                            this.form.radio1 = '视频'
                            this.form.radio2 = '欣赏'
                            break
                        case 2:
                            this.form.radio1 = '视频'
                            this.form.radio2 = '展示'
                            break
                        case 3:
                            this.form.radio1 = '音频'
                            this.form.radio2 = '欣赏'
                            break
                        case 4:
                            this.form.radio1 = '音频'
                            this.form.radio2 = '展示'
                            break
                        case 5:
                            this.form.radio1 = '文章'
                            this.form.radio2 = '欣赏'
                            break
                        case 6:
                            this.form.radio1 = '文章'
                            this.form.radio2 = '展示'
                            break
                    }
                }
            }).catch()
        },
        methods: {
            submit() {
                if (this.form.name == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入分类名称',
                        offset: 60
                    })
                    this.$refs['name'].focus()
                    return false
                }
                if (this.form.sort == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入分类排序',
                        offset: 60
                    })
                    this.$refs['sort'].focus()
                    return false
                }
                put('/modifyType', this.form).then(res => {
                    const result = res.data
                    if (result.code == 200) {
                        this.$notify.success({
                            title: '系统提示',
                            message: '分类修改成功',
                            offset: 60
                        })
                        this.$router.push('/type')
                    }
                }).catch()
            },
            cancel() {
                this.$router.push('/type')
            }
        }
    }
</script>

<style scoped>

</style>